package com.zwps.biz.controller.http;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwps.biz.api.model.vo.structure.FileCommentVO;
import com.zwps.biz.dal.db.object.PubCommonFileDO;
import com.zwps.biz.dal.db.object.ZTrainRecordDO;
import com.zwps.biz.domain.service.PubCommonFileService;
import com.zwps.biz.domain.service.ZTrainRecordService;
import com.zwps.common.controller.response.message.ResponseDataMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "四制（治）")
@RestController
@RequestMapping("structure/law")
@Validated
public class PubCommonFileController {
    @Autowired
    private PubCommonFileService fileService;
    @Autowired
    private ZTrainRecordService zTrainRecordService;

    @Operation(summary = "获取文件")
    @GetMapping("pubCommonFile/getList")
    public ResponseDataMessage pubCommonFileGetList(PubCommonFileDO fileDO) {

        return ResponseDataMessage.data(fileService.pubCommonFileGetList(fileDO));
    }

    @Operation(summary = "获取法律法规")
    @GetMapping("getList")
    public ResponseDataMessage getList() {
        return ResponseDataMessage.data(fileService.getFileList());
    }

    @Operation(summary = "获取法律法规理论培训记录")
    @GetMapping("getTrainList")
    public Page<ZTrainRecordDO> getTrainList(
            @RequestParam(value = "content", required = false) String content,
            @RequestParam(value = "year", required = false) String year,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        Page<ZTrainRecordDO> pageInfo = new Page<>(page, size);
        return zTrainRecordService.page(pageInfo, new LambdaQueryWrapper<ZTrainRecordDO>()
//                .like(StringUtils.hasText(content), ZTrainRecordDO::getContent, content)
                        .eq(ZTrainRecordDO::getType, 3)
                        .eq(ZTrainRecordDO::getIsDelete, 0)
                .apply("YEAR(train_time) = {0}", year)
                .orderByDesc(ZTrainRecordDO::getTrainTime)
        );
    }
}
